package com.wcr.school.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wcr.school.pojo.Grade;
import com.wcr.school.service.GradeService;
import com.wcr.school.util.Result;
import com.wcr.school.util.ResultCodeEnum;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/sms/gradeController")
public class GradeController {
    @Autowired
    GradeService gradeService;
    @GetMapping("/getGrades/{pageNo}/{pageSize}")
    public Result getGrades(
        @PathVariable("pageNo") Integer pageNo,
        @PathVariable("pageSize") Integer pageSize,
        String gradeName
    )
    {
        //分页，带条件查询
        Page<Grade> page = new Page<>(pageNo,pageSize);
        //通过服务层
        IPage<Grade> iPage = gradeService.getGradeByOption(page,gradeName);
        //封装return返回
        return Result.ok(iPage);

    }

    @PostMapping("/saveOrUpdateGrade")
    public Result saveOrUpdateGrade(@RequestBody Grade grade){
        gradeService.saveOrUpdate(grade);
        return Result.ok();
    }

    @DeleteMapping("/deleteGrade")
    public Result deleteGrade(@RequestBody List<Integer> list){
        gradeService.deleteGrade(list);
        return Result.ok();
    }

    @GetMapping("/getGrades")
    public Result getGrades(){
        List<Grade> list = gradeService.getAllGradeName();
        return Result.ok(list);
    }
}
